<script setup lang="ts">
import { useNaiveForm } from '@/hooks/common/form';
import { $t } from '@/locales';

defineOptions({
  name: 'TenantSearch'
});

interface Emits {
  (e: 'reset'): void;
  (e: 'search'): void;
}

const emit = defineEmits<Emits>();

const { formRef, validate, restoreValidation } = useNaiveForm();

const model = defineModel<Api.Business.OrdersSearchParams>('model', { required: true });

async function reset() {
  await restoreValidation();
  emit('reset');
}

async function search() {
  await validate();
  emit('search');
}

const payTypeOptions = [
  { value: '支付宝', label: '支付宝' },
  { value: '微信支付', label: '微信支付' },
  { value: '易支付', label: '易支付' }
];
</script>

<template>
  <NCard :bordered="false" size="small" class="card-wrapper">
    <NCollapse>
      <NCollapseItem :title="$t('common.search')" name="user-search">
        <NForm ref="formRef" :model="model" label-placement="left" :label-width="120">
          <NGrid responsive="screen" item-responsive>
            <NFormItemGi span="24 s:12 m:6" label="ID" path="id" class="pr-24px">
              <NInput v-model:value="model.id" placeholder="请输入ID" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="订单ID" path="orderId" class="pr-24px">
              <NInput v-model:value="model.orderId" placeholder="请输入订单ID" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="代理人" path="username" class="pr-24px">
              <NInput v-model:value="model.username" placeholder="请输入代理人账号" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="商家交易流水号" path="merchantTransactionId" class="pr-24px">
              <NInput v-model:value="model.merchantTransactionId" placeholder="请输入商家交易流水号" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="产品名称" path="productName" class="pr-24px">
              <NInput v-model:value="model.productName" placeholder="请输入产品名称" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="支付方式" path="payWay" class="pr-24px">
              <NSelect
                v-model:value="model.payWay"
                :options="payTypeOptions"
                placeholder="请选择支付方式"
                clearable
              ></NSelect>
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="创建时间" path="createTime" class="pr-24px">
              <NDatePicker v-model:value="model.createTime" type="datetime" clearable />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="支付状态" path="payStatus" class="pr-24px">
              <NInput v-model:value="model.payStatus" placeholder="请输入支付状态" />
            </NFormItemGi>
            <NFormItemGi span="24" class="pr-24px">
              <NSpace class="w-full" justify="end">
                <NButton @click="reset">
                  <template #icon>
                    <icon-ic-round-refresh class="text-icon" />
                  </template>
                  {{ $t('common.reset') }}
                </NButton>
                <NButton type="primary" ghost @click="search">
                  <template #icon>
                    <icon-ic-round-search class="text-icon" />
                  </template>
                  {{ $t('common.search') }}
                </NButton>
              </NSpace>
            </NFormItemGi>
          </NGrid>
        </NForm>
      </NCollapseItem>
    </NCollapse>
  </NCard>
</template>

<style scoped></style>
